package com.haina.shop.controller.user;
import com.haina.shop.dto.OrderListDTO;
import com.haina.shop.dto.OrderParamDTO;
import com.haina.shop.dto.PayDTO;
import com.haina.shop.dto.SubmitOrderParam;
import com.haina.shop.result.IPageIndexImg;
import com.haina.shop.result.ServiceResult;
import com.haina.shop.service.OrderService;
import com.haina.shop.vo.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
public class OrderController {
    @Autowired
    private OrderService service;
    /**
     * 获取我的订单订单数量
     */
    @GetMapping("/p/myOrder/orderCount")
    public ServiceResult<OrderCountVO> getOrderCount(){
        return service.getOrderCount();
    }

    /**
     * 根据订单状态获取订单列表信息，状态为0时获取所有订单
     * @param dto
     */
    @GetMapping("/p/myOrder/myOrder")
    public ServiceResult<IPageIndexImg<OrderVO>> getOrderList(OrderListDTO dto){
        return service.getOrderList(dto);
    }

    /**
     * 根据订单号获取订单详情信息
     * @param orderNumber
     */
    @GetMapping("/p/myOrder/orderDetail")
    public ServiceResult<OrderDetailVO> getOrderDetail(String orderNumber){
         return service.getOrderDetail(orderNumber);
    }

    /**
     * 根据订单号确认收货
     * @param orderNumber
     * @return
     */
    @PutMapping("/p/myOrder/receipt/{orderNumber}")
    public ServiceResult receiptByOrderNum(@PathVariable String orderNumber){
        return service.receiptByOrderNum(orderNumber);
    }

    /**
     * 根据订单号取消订单
     * @param orderNumber
     * @return
     */
    @PutMapping("/p/myOrder/cancel/{orderNumber}")
    public ServiceResult cancelByOrderNum(@PathVariable String orderNumber){
        return service.cancalByOrderNum(orderNumber);
    }
    /**
     * 根据订单号删除订单
     * @param orderNumber
     * @return
     */
    @DeleteMapping("/p/myOrder/{orderNumber}")
    public ServiceResult deleteByOrderNum(@PathVariable String orderNumber){
        return service.deleteByOrderNum(orderNumber);
    }

    /**
     * 传入下单所需要的参数进行下单
     * @param dto
     * @return
     */
    @PostMapping("/p/order/confirm")
    public ServiceResult<OrderConfirmVO> confirm(@RequestBody OrderParamDTO dto){

        return service.confirm(dto);
    }
    /**
     * 提交订单
     * @paramparam
     * @return
     */
    @PostMapping("/p/order/submit")
    public ServiceResult<OrderNumberVO> submit(@RequestBody SubmitOrderParam param){

        return service.submit(param);
    }

    /**
     * 支付
     * @return
     */
    @PostMapping("/p/order/pay")
    public ServiceResult pay(@RequestBody PayDTO dto){
          return service.pay(dto);
    }
}
